package com.jacky;

import com.jacky.cglib.CglibDynamicProxy;
import com.jacky.jdk.BookApi;
import com.jacky.jdk.JdkDynamicProxy;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import net.sf.cglib.reflect.FastClass;
import net.sf.cglib.reflect.FastMethod;

import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: jacky
 * @date: 2018/6/4
 * Time: 13:50
 * Description:
 **/
public class Main {

    public static void main(String[] args) throws Exception {

        JdkDynamicProxy jdkDynamicProxy = new JdkDynamicProxy();
        CglibDynamicProxy cglibDynamicProxy = new CglibDynamicProxy();
        long time = System.currentTimeMillis();
        BookApi jdkProxy = jdkDynamicProxy.createJdkDynamicProxy();
        time = System.currentTimeMillis() - time;
        System.out.println("Create JDK Proxy: " + time + " ms");

        time = System.currentTimeMillis();
        BookApi cglibProxy = cglibDynamicProxy.createCglibDynamicProxy();
        time = System.currentTimeMillis() - time;
        System.out.println("Create CGLIB Proxy: " + time + " ms");

        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            jdkProxy.sell();
        }
        System.out.println("JDK Proxy invoke cost " + (System.currentTimeMillis() - start) + " ms");


        start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            cglibProxy.sell();
        }
        System.out.println("CGLIB Proxy invoke cost " + (System.currentTimeMillis() - start) + " ms");
    }

}